<?php
/**
 * This is a quick-and-dirty draft QPanel object to do Create, Edit, and Delete functionality
 * of the ComSchool class.  It uses the code-generated
 * ComSchoolMetaControl class, which has meta-methods to help with
 * easily creating/defining controls to modify the fields of a ComSchool columns.
 *
 * Any display customizations and presentation-tier logic can be implemented
 * here by overriding existing or implementing new methods, properties and variables.
 *
 * NOTE: This file is overwritten on any code regenerations.  If you want to make
 * permanent changes, it is STRONGLY RECOMMENDED to move both com_school_edit.php AND
 * com_school_edit.tpl.php out of this Form Drafts directory.
 *
 * @package My QCubed Application
 * @subpackage Drafts
 */
class ComSchoolEditPanel extends QPanel {
    //Local instance of the ComSchoolMetaControl
    protected $mctComSchool;

    //Controls for ComSchool's Data Fields

    public $calDate;
    public $lstTypeObject;
    public $txtEvent;
    public $lstSample;


    //Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
    public $lstPeopleAsCom;

    //Other Controls
    public $btnSave;
    public $btnDelete;
    public $btnCancel;

    //Callback
    protected $strClosePanelMethod;

    public function PersonOrg_Change($strParameter) {
        $objMemberArray = Person::QueryArray(
                QQ::AndCondition(
                QQ::Equal(QQN::Person()->Org, $_SESSION['OrgId'] ),
                QQ::OrCondition(
                QQ::Like(QQN::Person()->FirstName, $strParameter . '%'),
                QQ::Like(QQN::Person()->LastName, $strParameter . '%')
                )
                ),
                QQ::Clause(QQ::OrderBy(QQN::Person()->FirstName))

        );
        $result = array();
        foreach($objMemberArray as $objMember) {
            $result[] = $objMember->FirstName .  " ".  $objMember->LastName . "|" . $objMember->Id ;
        }
        return $result;
    }
    public function __construct($objParentObject, $strClosePanelMethod, $intId = null, $strControlId = null) {
        // Call the Parent
        try {
            parent::__construct($objParentObject, $strControlId);
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }

        // Setup Callback and Template
        $this->strTemplate = __DOCROOT__.__COM__ .  '/tpl/QePanel_edit.tpl.php';
        $this->strClosePanelMethod = $strClosePanelMethod;


        // MAKE SURE we specify "$this" as the MetaControl's (and thus all subsequent controls') parent
        $this->mctComSchool = ComSchoolMetaControl::Create($this, $intId);

        //Create the Record Info for this record
        $objEditPanel = new ComSchoolInfoPanel ($this, $this->mctComSchool);
        $this->objForm->SetEditPane($objEditPanel, "pnlComInfo");


        // Call MetaControl's methods to create qcontrols based on ComSchool's data fields

        $this->calDate = $this->mctComSchool->calDate_Create();

        $this->lstTypeObject = $this->mctComSchool->lstTypeObject_Create();

        $this->txtEvent = $this->mctComSchool->txtEvent_Create();

        $this->lstPeopleAsCom = $this->mctComSchool->lstPeopleAsCom_Create();
        $this->lstPeopleAsCom->Height= 80;


        // Create Buttons and Actions on this Form
        $this->btnSave = new QButton($this);
        $this->btnSave->Text = QApplication::Translate('Save');
        $this->btnSave->Name = QApplication::Translate('Save');
        $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSave_Click'));
        $this->btnSave->CausesValidation = $this;

        $this->btnCancel = new QButton($this);
        $this->btnCancel->Text = QApplication::Translate('Cancel');
        $this->btnCancel->Name = QApplication::Translate('Cancel');
        $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnCancel_Click'));

        $this->btnDelete = new QButton($this);
        $this->btnDelete->Text = QApplication::Translate('Delete');
        $this->btnDelete->Name = QApplication::Translate('Delete');
        $this->btnDelete->AddAction(new QClickEvent(), new QConfirmAction(QApplication::Translate('Are you SURE you want to DELETE this') . ' ' . QApplication::Translate('ComSchool') . '?'));
        $this->btnDelete->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
        $this->btnDelete->Visible = $this->mctComSchool->EditMode;

        //change tab
        $this->objForm->tabMain->ChangeTabById(1,0);
    }

    // Control AjaxAction Event Handlers
    public function btnSave_Click($strFormId, $strControlId, $strParameter) {
        // Delegate "Save" processing to the ComSchoolMetaControl
        $this->mctComSchool->SaveComSchool();
        $this->CloseSelf(true);
    }

    public function btnDelete_Click($strFormId, $strControlId, $strParameter) {
        // Delegate "Delete" processing to the ComSchoolMetaControl
        $this->mctComSchool->DeleteComSchool();
        $this->CloseSelf(true);
    }

    public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
        $this->CloseSelf(false);

    }

    public function Validate() {
        $blnToReturn = true;
        /*

                    if ($this->lstTypeObject->SelectedValue  == "Fax"){
                        $this->lstTypeObject->Warning="No Fax";
                        $blnToReturn=false;
                    }
        */

        $blnFocused = false;
        /*
                    foreach ($this-> GetErrorControls() as $objControl) {

                            // Set Focus to the top-most invalid control
                            if (!$blnFocused) {
                                    $objControl->Focus();
                                    $blnFocused = true;
                                    $this->tabMainPanel->ActiveTab =  $objControl->ParentControl->__get("CurrentSection") -1;
                            }
                            $objControl->Blink();
                     * 
        */

        return $blnToReturn;
    }
    // Close Myself and Call ClosePanelMethod Callback
    protected function CloseSelf($blnChangesMade) {
        $strMethod = $this->strClosePanelMethod;
        $this->objForm->CloseAllPane($blnChangesMade);

    }




}
?>